package com.lagou.edu.component;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

/**
 * @program: stage-3-module-5
 * @description:
 * @author: zhangxiaoyang
 * @date: 2020-09-22 15:56
 **/
@Configuration
@RefreshScope
@Data
@ConfigurationProperties(prefix = "spring.mail")
public class MailConfig {

    private String host;
    private String username;
    private String password;
    private String defaultEncoding;
    private Properties javaMailProperties = new Properties();


    @Bean
    public JavaMailSender javaMailSender(){
        JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
        javaMailSender.setDefaultEncoding(defaultEncoding);
        javaMailSender.setHost(host);
        javaMailSender.setPassword(password);
        javaMailSender.setUsername(username);
        return javaMailSender;
    }
}
